package com.ychug.gateway.webutil;

import com.ychug.common.mapper.JsonMapper;
import com.ychug.framework.util.SpringContextHolder;
import com.ychug.service.system.entity.SysDictDataEntity;
import com.ychug.service.system.service.ISysDictDataService;
import com.ychug.service.system.service.impl.SysDictDataServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * 后台管理页面的公共类
 *
 */
public class SysWebUtil {

   public static  ISysDictDataService mISysDictDataService = SpringContextHolder.getBean(SysDictDataServiceImpl.class);


    /**
     * 根据字典类型查询字典数据
     * @param type
     * @return
     */
    public static List<SysDictDataEntity> getDictDataByTypeList(String type){
        List<SysDictDataEntity> list = mISysDictDataService.selectDictDataByType(type);
        System.out.println(list);
        return list;
    }

    /**
     * 返回字典列表（JSON）
     * @param type
     * @return
     */
    public static String getDictDataByTypeListJson(String type){
        return JsonMapper.toJsonString(getDictDataByTypeList(type));
    }



    public static void main(String[] args) {
        SysDictDataEntity d = new SysDictDataEntity();
        d.setDictLabel("222");
        d.setDictType("12");
        d.setDictCode(34l);
        List<SysDictDataEntity> list = new ArrayList<SysDictDataEntity>();
        list.add(d);
       String s =  JsonMapper.toJsonString(list);
        System.out.println(s);
    }


}
